﻿using UnityEngine;
using System.Collections;
using UnityEditor;

public class MapEditWindow : EditorWindow
{


    public GameObject terrain;


    public string level_id;
    public enum BattleStyle
    {
        kill,
        idle,
        jump
    }
    public enum MonsterType
    {
        OnTriggerAn,
        Others
    }

    public class MonsterGroup
    {
        public float triggerMonster_FixTime;
        public GameObject triggerMonster_object;
        public GameObject triggerMonsterGroup;
        public int birthNum;
        public int x_gap;
        public MonsterProperty[] mp = new MonsterProperty[6];
    }

    public struct MonsterProperty
    {
        public Transform pos;
        public int monsterId;
        public int replaceId;
    }

    #region level property
    public Transform levelPos;

    public BattleStyle battleStyle = BattleStyle.kill;
    public float passLevelTime;
    public Transform bossTargetPos;

    public MonsterType mousterType = MonsterType.OnTriggerAn;
    public float monsterFixTime;
    public int maxMonster;

    public Transform birthPos;

    Transform cameraBirthPos;

    public GameObject sideStop;
    public GameObject sideStopPrefab;
    public GameObject[] sideStopPrefabs;

    public GameObject monsterAppearGroup;

    public int triggerMonsterGroupCount = 0;
    public MonsterGroup[] MG;
    #endregion

    private static GUIContent
     insertContent = new GUIContent("+", "新建一片"),
     deleteContent = new GUIContent("-", "移除");

    private static GUILayoutOption
     buttonWidth = GUILayout.MaxWidth(100f), objectWidth = GUILayout.MaxWidth(500f);

    private static bool[] folds = { false, true, true, false, true, true, false, false };

    //	private SerializedProperty prefabs;

    [MenuItem("Map/MyMapWindow")]

    public static void ShowWindow()
    {
        EditorWindow.GetWindow(typeof(MapEditWindow)).title = "地图编辑器";
    }

    //	void OnEnable()
    //	{
    //	 prefabs=(SerializedProperty)sideStopPrefabs;
    //	}

    void OnGUI()
    {
        terrain = (GameObject)EditorGUILayout.ObjectField("关卡地图模型", terrain, typeof(GameObject), true);

        GUILayout.BeginHorizontal();
        level_id = (string)EditorGUILayout.TextField("输入关卡ID，新建关卡", level_id);
        if (GUILayout.Button("添加小关卡", buttonWidth)) { }
        GUILayout.Label("关卡ID和关卡地图模型不能为null,才能新建关卡");
        GUILayout.EndHorizontal();

        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("折叠")) { }
        EditorGUILayout.TextField("本关卡ID", level_id);
        if (GUILayout.Button("移除本关卡")) { };
        EditorGUILayout.EndHorizontal();


        EditorGUILayout.ObjectField("本关卡地图模型", terrain, typeof(GameObject), true);
        levelPos = (Transform)EditorGUILayout.ObjectField("本关卡节点：", levelPos, typeof(Transform), true, objectWidth);

        EditorGUILayout.BeginHorizontal();
        battleStyle = (BattleStyle)EditorGUILayout.EnumPopup("本关卡战斗类型： ", battleStyle);
        passLevelTime = EditorGUILayout.FloatField("通关时间", passLevelTime);
        bossTargetPos = (Transform)EditorGUILayout.ObjectField("Boss移动目标点： ", bossTargetPos, typeof(Transform), true, objectWidth);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        mousterType = (MonsterType)EditorGUILayout.EnumPopup("刷怪类型", mousterType);
        monsterFixTime = EditorGUILayout.FloatField("刷怪间隔时间:", monsterFixTime);
        maxMonster = EditorGUILayout.IntField("刷怪上限", maxMonster);
        EditorGUILayout.EndHorizontal();

        birthPos = (Transform)EditorGUILayout.ObjectField("出生点：   ", birthPos, typeof(Transform), true, objectWidth);

        folds[0] = EditorGUILayout.BeginToggleGroup("添加摄像机", folds[0]);
        if (folds[0])
        {
            EditorGUILayout.BeginHorizontal();
            cameraBirthPos = (Transform)EditorGUILayout.ObjectField("摄像机出生点： ", cameraBirthPos, typeof(Transform), true, objectWidth);
            if (GUILayout.Button("关闭")) { }
            if (GUILayout.Button("同步出生点")) { };
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();
        sideStop = (GameObject)EditorGUILayout.ObjectField("边界遮挡物 ", sideStop, typeof(GameObject), true, objectWidth);
        sideStopPrefab = (GameObject)EditorGUILayout.ObjectField("边界遮挡物预设", sideStopPrefab, typeof(GameObject), true, objectWidth);

        //	 if(GUILayout.Button(insertContent, buttonWidth))
        //	 {
        //	 prefabs.arraySize++;
        //	 }
        EditorGUILayout.EndHorizontal();



        //	 EditorGUILayout.BeginVertical();
        //	 for(int i=0;i<prefabs.arraySize;i++)
        //	 {
        //	 SerializedProperty s=prefabs.GetArrayElementAtIndex(i);
        //	 EditorGUILayout.BeginHorizontal();
        //	 EditorGUILayout.PropertyField(s);
        //	 if(GUILayout.Button(deleteContent, buttonWidth))
        //	 {
        //	 prefabs.DeleteArrayElementAtIndex(i);
        //	 }
        //	 EditorGUILayout.EndHorizontal();
        //	 }
        //	 EditorGUILayout.EndVertical();

        EditorGUILayout.BeginHorizontal();
        monsterAppearGroup = (GameObject)EditorGUILayout.ObjectField("怪物出现组群：", monsterAppearGroup, typeof(GameObject), true);
        if (GUILayout.Button("新建一组"))
        {
            triggerMonsterGroupCount++;
            Debug.Log(triggerMonsterGroupCount);
        }
        EditorGUILayout.EndHorizontal();

        MG = new MonsterGroup[triggerMonsterGroupCount];

        //	 EditorGUILayout.BeginVertical();
        //	 for(int i=0;i<triggerMonsterGroupCount;i++)
        //	 {
        //	 EditorGUILayout.BeginHorizontal();
        //	 MG[i].triggerMonster_FixTime=EditorGUILayout.FloatField("刷怪的间隔时间",MG[i].triggerMonster_FixTime);
        //	 MG[i].triggerMonster_object=(GameObject)EditorGUILayout.ObjectField("触发怪物的物体 ",MG[i].triggerMonster_object,typeof(GameObject),true);
        //	 MG[i].triggerMonsterGroup=(GameObject)EditorGUILayout.ObjectField("出怪组"+(i+1).ToString(),MG[i].triggerMonsterGroup,typeof(GameObject),true);
        //	 MG[i].birthNum=EditorGUILayout.IntField("生成个数",MG[i].birthNum);
        //	 MG[i].x_gap=EditorGUILayout.IntField("X宽度距离",MG[i].x_gap);
        //	 EditorGUILayout.EndHorizontal();
        //
        //	 EditorGUILayout.BeginVertical();
        //	 for(int j=0;j<MG[i].mp.Length;j++)
        //	 {
        //	 EditorGUILayout.BeginHorizontal();
        //	 MG[i].mp[j].pos=(Transform)EditorGUILayout.ObjectField(MG[i].mp[j].pos,typeof(Transform),true);
        // MG[i].mp[j].monsterId=EditorGUILayout.IntField(MG[i].mp[j].monsterId);
        // MG[i].mp[j].replaceId=EditorGUILayout.IntField(MG[i].mp[j].replaceId);
        //	 EditorGUILayout.EndHorizontal();
        //	 }
        //	 EditorGUILayout.EndVertical();
        //	 }
        //	 EditorGUILayout.EndVertical();

    }

}
